#定义家具类
class HouseItem:
    def __init__(self,name,area):
        self.name = name
        self.area = area
    def __str__(self):
        return "{}占地面积{}".format(self.name,self.area)  
    def __repr__(self):
        return "{}占地面积{}".format(self.name,self.area)  
    
#定义房子类
class house:
    def __init__(self,address,area):
        self.address = address
        self.area = area
        self.free_area = area
        self.item_list = []
    def add_item(self,item:HouseItem):
        print("要添加的家具是{}".format(item.name))
        if self.free_area >= item.area:
            self.item_list.append(item)
            print("添加成功")
            #修改面积
            self.free_area -= item.area
        else:
            print("添加失败")   
    def __str__(self):
        return ("房子所在地址是{},占地{},剩余面积{}".format(self.address,self.area,self.free_area))
    
        
shafa=HouseItem("沙发",20)
chaji=HouseItem("茶几",10)
chuang=HouseItem("床",30)
home=house("深圳宝安",100)
print(home)
home.add_item(shafa)
home.add_item(chaji)
home.add_item(chuang)
print(home)
print(home.item_list)